cmake_minimum_required(VERSION 3.16)

project(RPIUI VERSION 0.1 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 判断目标架构
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm")
    set(CMAKE_SYSTEM_NAME Linux)          # 目标架构为 ARM (例如 Raspberry Pi)
    set(CMAKE_SYSTEM_PROCESSOR arm)
else()
    set(CMAKE_SYSTEM_NAME Linux)          # 目标架构为 x86_64 或其他
    set(CMAKE_SYSTEM_PROCESSOR x86_64)
endif()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pg")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")

set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Qt6 6.5 REQUIRED COMPONENTS Quick Quick3D)

qt_standard_project_setup(REQUIRES 6.5)
set(CMAKE_AUTORCC ON) # CMAKE 自动处理资源文件
# 添加资源文件
qt6_add_resources(SOURCES resource/resource.qrc)

# 设置头文件搜索路径
include_directories(/home/ding/qt6/pi/include)

set(HEADER_FILES 
    ./src/interface/InterFace.h
    ./src/log/Log.h
)
set(SOURCES_FILES 
    ./src/interface/InterFace.cpp
    ./src/log/Log.cpp
)

set(QML_FILES
    qml/Home.qml 
    qml/Setting.qml
    qml/Rpi.qml
    qml/Test.qml
    qml/CustomControls/SlidingArea.qml
    qml/CustomControls/SliderBar.qml
    qml/CustomControls/EmitterCustomShapes.qml
    qml/CustomControls/ButtonControls.qml
)

qt_add_executable(appRPIUI
    ./src/main.cpp
    ${SOURCES}
    
)

qt_add_qml_module(appRPIUI
    URI RPIUI
    VERSION 1.0
    QML_FILES
        qml/Main.qml
        ${QML_FILES} 
    SOURCES
    ${HEADER_FILES}
    ${SOURCES_FILES}
)


if(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm")
set_target_properties(appRPIUI PROPERTIES
    INSTALL_RPATH "/usr/local/qt6/lib"  # 可执行文件的 运行时库搜索路径（RPATH）
    BUILD_WITH_INSTALL_RPATH TRUE  # 在链接时就找到库路径 /usr/local/qt6/lib
)
endif()


target_link_libraries(appRPIUI
    PRIVATE Qt6::Quick
)

include(GNUInstallDirs)
install(TARGETS appRPIUI
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
